package com.github.cakin.shiro.chapter17.service;

import com.github.cakin.shiro.chapter17.dao.ClientDao;
import com.github.cakin.shiro.chapter17.entity.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

/**
 * @className: ClientService
 * @description: ClientServiceImpl
 * @date: 2020/5/27
 * @author: cakin
 */
@Transactional
@Service
public class ClientServiceImpl implements ClientService {
    /**
     * 注入clientDao
     */
    @Autowired
    private ClientDao clientDao;

    /**
     * 功能描述：创建客户端
     *
     * @param client 客户端
     * @return Client 客户端
     * @author cakin
     * @date 2020/5/27
     */
    public Client createClient(Client client) {
        client.setClientId(UUID.randomUUID().toString());
        client.setClientSecret(UUID.randomUUID().toString());
        return clientDao.createClient(client);
    }
    /**
     * 功能描述：更新客户端
     *
     * @param client 客户端
     * @return Client 客户端
     * @author cakin
     * @date 2020/5/27
     */
    public Client updateClient(Client client) {
        return clientDao.updateClient(client);
    }
    /**
     * 功能描述：删除客户端
     *
     * @param clientId 客户端Id
     * @author cakin
     * @date 2020/5/27
     */
    public void deleteClient(Long clientId) {
        clientDao.deleteClient(clientId);
    }
    /**
     * 功能描述：根据客户端Id主键查找客户端
     *
     * @param clientId 客户端
     * @return Client 客户端
     * @author cakin
     * @date 2020/5/27
     */
    public Client findOne(Long clientId) {
        return clientDao.findOne(clientId);
    }
    /**
     * 功能描述：找到所有客户端
     *
     * @return List<Client> 客户端列表
     * @author cakin
     * @date 2020/5/27
     */
    public List<Client> findAll() {
        return clientDao.findAll();
    }
    /**
     * 功能描述：根据客户端业务键Id查找客户端
     *
     * @param clientId 客户端
     * @return Client 客户端
     * @author cakin
     * @date 2020/5/27
     */
    public Client findByClientId(String clientId) {
        return clientDao.findByClientId(clientId);
    }
    /**
     * 功能描述：根据客户端密钥查找客户端
     *
     * @param clientSecret 客户端密钥
     * @return Client 客户端
     * @author cakin
     * @date 2020/5/27
     */
    public Client findByClientSecret(String clientSecret) {
        return clientDao.findByClientSecret(clientSecret);
    }
}
